﻿//********************************************************************************//
//创建日期：<创建日期，2016-04-26>
//创建作者：<郭登杰，guodengjie@shanghai3h.com>
//功能说明：三同时查询
//********************************************************************************//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;
using BLL;
using BLL.Access;
using System.Data;
using Platform.Http;
using Web.Class;

namespace Web.Pages.YongShui.SanTongSGL
{
    public partial class SanTongSCX : BasePage
    {
        #region 属性

        /// <summary>
        /// 记录查询结果集
        /// </summary>
        private DataTable dtSource
        {
            get
            {
                return ViewState["dtSource"] as DataTable;
            }
            set
            {
                ViewState["dtSource"] = value;
            }
        }

        /// <summary>
        ///当前操作项ID
        /// </summary>
        private int SANTONGSID
        {
            get
            {
                return Convert.ToInt32(ViewState["SANTONGSID"]);
            }
            set
            {
                ViewState["SANTONGSID"] = value;
            }
        }

        #endregion

        #region 变量

        /// <summary>
        /// 水平衡管理实体对象
        /// </summary>
        YS_STS_SANTONGSGL _YS_STS_SANTONGSGL = new YS_STS_SANTONGSGL();
        
        /// <summary>
        /// 水平衡管理BLL对象
        /// </summary>
        YS_STS_SANTONGSGLBLL _YS_STS_SANTONGSGLBLL = new YS_STS_SANTONGSGLBLL();

        /// <summary>
        /// 数据访问操作类
        /// </summary>
        SpHelper _spHelper = new SpHelper();

        /// <summary>
        /// 用户信息对象
        /// </summary>
        YS_YG_YONGHUXX _YS_YG_YONGHUXX = new YS_YG_YONGHUXX();

        /// <summary>
        /// 用户信息BLL
        /// </summary>
        YS_YG_YONGHUXXBLL _YS_YG_YONGHUXXBLL = new YS_YG_YONGHUXXBLL();

        /// <summary>
        /// DataTable的行集合
        /// </summary>
        DataRowCollection drc;

        /// <summary>
        /// 操作日志BLL
        /// </summary>
        SYS_LOGBLL _SYS_LOGBLL = new SYS_LOGBLL();

        #endregion

        #region 事件

        /// <summary>
        /// 页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            //第一次页面加载
            if (!IsPostBack)
            {
                InitControl();
            }
            else
            {
                this.gvSANTONGSHI.DataSource=this.dtSource;
                this.gvSANTONGSHI.DataBind();
            }
        }

        /// <summary>
        /// 绑定空表头
        /// </summary>
        protected override void Render(HtmlTextWriter sender)
        {
            base.Render(sender); 
        }       

        /// <summary>
        /// 查询按钮事件
        /// </summary>
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            LoadData(true);
        }

        /// <summary>
        /// 响应前台回调
        /// </summary>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            CallbackResult cr = new CallbackResult(e.Parameter);
            int id = Convert.ToInt32(this.hdCollection.Get("ID"));
            if (e.Parameter == "info")
            {
                this._YS_STS_SANTONGSGL = this._YS_STS_SANTONGSGLBLL.SelectYS_STS_SANTONGSGL(id);
                DataRowCollection drc=new YS_YG_YONGHUXXBLL().SelectYS_YG_YONGHUXXesDynamic("I_LEIXING=1 AND S_YONGHUH="+_YS_STS_SANTONGSGL.S_YONGHUH,null).Rows;
                if(drc.Count!=1)
                {
                    cr.IsSuccess=false;
                    cr.Msg="该用月下月信息不正确。";
                    cr.IsAlertMsg=true;
                    e.Result=cr.ToString();
                    return;
                }
                DataRow dr=drc[0];
                cr.IsSuccess = true;
                cr.IsAlertMsg = false;
                cr.AddValue(_YS_STS_SANTONGSGL.S_YONGHUH, dr["S_YONGHUM"], dr["S_DIZHI"], _YS_STS_SANTONGSGL.S_PINGGUDW, _YS_STS_SANTONGSGL.I_SHEJISL, _YS_STS_SANTONGSGL.I_PINGGUSL, _YS_STS_SANTONGSGL.I_CHAZHI, _YS_STS_SANTONGSGL.I_ZHONGSHUI, _YS_STS_SANTONGSGL.I_YUSHUI, _YS_STS_SANTONGSGL.I_PILOUJG, _YS_STS_SANTONGSGL.D_RIQI.Value.ToString("yyyy-MM-dd"));
                e.Result = cr.ToString();
                return;
            }        
        }


        #endregion

        #region 方法

        /// <summary>
        /// 初始化控件
        /// </summary>
        private void InitControl()
        {
            
        }

        /// <summary>
        /// 数据加载
        /// </summary>
        private void LoadData(bool  reGet)
        {
            if (reGet)
            {
                this.dtSource = _spHelper.P_YS_GETSANTONGS(this.contxtYongHuH.Text.Trim() == "" ? null : this.contxtYongHuH.Text.Trim(), this.contxtYongHuM.Text.Trim() == "" ? null : this.contxtYongHuM.Text.Trim(), this.contxtDiZhi.Text.Trim() == "" ? null : this.contxtDiZhi.Text.Trim(), this.contxtSheJiSL.Text == "" ? null : (int?)int.Parse(this.contxtSheJiSL.Text), this.contxtPingGuSL.Text == "" ? null : (int?)int.Parse(this.contxtPingGuSL.Text)).Tables[0];            
            }
            this.gvSANTONGSHI.DataSource = this.dtSource;
            this.gvSANTONGSHI.DataBind();            
        }

        #endregion
    }
}